home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ptv1n1.arc / READCARD.PAS < prev    next >
Pascal/Delphi Source File  |  1990-06-08  |  3KB  |  85 lines

  1. (*
  2. **    File:    readcard.pas
  3. **    Purpose: Read and display data in a card file.
  4. **    Author:  (c) 1989 by Tom Swan. All rights reserved.
  5. *)
  6.  
  7. program ReadCard;
  8.  
  9. uses Crt, Objects, Forms, Sliders, UNewType, Cards, UFormGen;
  10.  
  11. { ---- Halt program with an error message }
  12. procedure error( message : string );
  13. begin
  14.    writeln;
  15.    writeln( 'ERROR: ', message );
  16.    halt( 1 )
  17. end; { error }
  18.  
  19. { ---- Load cards and field definitions into memory }
  20. procedure ReadCards;
  21. var   
  22.    header: LongInt;     { Card file signature header }
  23. begin
  24. {- Open the stream }
  25.    theStream.init( paramStr(1), SOPEN, 1024 );
  26. {- Test status of previous init }
  27.    if theStream.Status <> 0 
  28.       then error( 'Can''t open ' + paramStr(1) );
  29. {- Read and verify header }
  30.    theStream.read( header, SizeOf( LongInt) );
  31.    if header <> SIGNATURE 
  32.       then error( 'Not a card file' );
  33. {- Load the field definitions and cards }
  34.    theForm.load( theStream );
  35.    theCards.load( theStream );
  36.    if theStream.Status <> 0 
  37.       then error('Disk read error');
  38. end; { ReadCards }
  39.  
  40. { ---- Display field titles and data in each card }
  41. procedure DisplayCards;
  42. var
  43.    i, j : integer;   { For-loop and temp vars }
  44.    s : FString;      { String for displaying data }
  45.    p : NodePtr;      { Recast to field object type }
  46. begin
  47. {- Loop for however many cards are in memory }
  48.    for i := 1 to theCards.Count do
  49.    begin
  50.    {- Transfer one card to field list }
  51.       theForm.Put( theCards.CardData^ );
  52.    {- Assign address of first field to p }
  53.       p := theForm.Fields.First;
  54.       while p <> nil do
  55.       begin
  56.       {- Can't display slider fields as text! }
  57.          if TypeOf( p^ ) <> TypeOf( FSlider ) then
  58.          begin
  59.          {- Assign and display field title }
  60.             s := FTextPtr( p )^.Title^;
  61.             j := pos( ':', s );
  62.             if j <> 0 then delete( s, j, 1 );
  63.             if length( s ) > 12 then s := copy( s, 1, 12 );
  64.             write( s, ' ':13 - length(s), ': ' );
  65.          {- Load field data into string s and display it }
  66.             FTextPtr( p )^.GetStr( s );
  67.             writeln( s );
  68.          end; { if }
  69.          {- Get next field. If last, p will = nil }
  70.          p := theForm.Fields.Next( p );
  71.       end; { while }
  72.       {- Move 'Current' pointer to next card }
  73.       theCards.Next;
  74.       writeln;
  75.       write( 'Press ENTER to continue...' );
  76.       readln;
  77.    end; { for }
  78. end; { DisplayCards }
  79.  
  80. begin
  81.    ReadCards;        {- Load fields and cards into memory }
  82.    DisplayCards;     {- Display card-file records }
  83.    theStream.Done;   {- Close the stream and clean up }
  84. end.
  85.